import request from '@/utils/request'

// 主机管理API
export const hostAPI = {
  // 获取主机列表
  getHosts(params?: any) {
    return request({
      url: '/api/hosts/',
      method: 'get',
      params
    })
  },

  // 获取主机详情
  getHostDetail(id: number) {
    return request({
      url: `/api/hosts/${id}/`,
      method: 'get'
    })
  },

  // 创建主机
  createHost(data: any) {
    return request({
      url: '/api/hosts/',
      method: 'post',
      data
    })
  },

  // 更新主机
  updateHost(id: number, data: any) {
    return request({
      url: `/api/hosts/${id}/`,
      method: 'put',
      data
    })
  },

  // 删除主机
  deleteHost(id: number) {
    return request({
      url: `/api/hosts/${id}/`,
      method: 'delete'
    })
  },

  // 测试主机连接
  testConnection(id: number) {
    return request({
      url: `/api/hosts/${id}/test_connection/`,
      method: 'post'
    })
  },

  // 获取主机组
  getHostGroups(params?: any) {
    return request({
      url: '/api/hostgroups/',
      method: 'get',
      params
    })
  },

  // 获取环境列表
  getEnvironments() {
    return request({
      url: '/api/environments/',
      method: 'get'
    })
  }
}

export default hostAPI
